{{extend "forums_layout.html"}}

{{block title}}{{=forum.name}}{{end}}

{{block forum_nav}}
    <ul class="breadcrumb">
      <li>
        <a href="{{=url_for('plugs.forums.views.ForumView.list')}}" class="home" title="{{=_('Forum Home')}}">{{=_('Forum Home')}}</a> <span class="divider">/</span>
      </li>
      <li class="active">
        <a href="{{=url_for('plugs.forums.views.ForumView.forum_index', id=forum.id)}}">{{=forum.name}}</a>
      </li>
    </ul>
    
    <form class="form-inline pull-right" action="" method="GET">
        <input type="text" class="input-large" name="term" value="{{=term}}">
        <label class="radio">
            <input type="radio" name="type" id="optionsRadios1" value="1" {{if type=="1":}}checked=""{{pass}}>
            {{=_('Subject')}}
        </label>
        <label class="radio">
            <input type="radio" name="type" id="optionsRadios2" value="2" {{if type=="2":}}checked=""{{pass}}>
            {{=_('Author')}}
        </label>
        <button type="submit" class="btn btn-primary">{{=_('Search')}}</button>
    </form>
    
    <div class="pull-left" style="margin-bottom:16px;">
        {{if request.user:}}
            {{if (forum.manager_only and forum.managers.has(request.user.id)) or not forum.manager_only:}}
                <a class="btn btn-success" href="{{=url_for('plugs.forums.views.ForumView.new_topic', id=forum.id)}}">{{=_('New Post')}}</a>
            {{else:}}
                <font color="red">{{=_('This forum has beed set as only forum manager can publish post!')}}</font>
            {{pass}}
        {{else:}}
        <font color="red">{{=_('Please sign in to post new subject!')}}</font>
        {{pass}}
    </div>
{{end}}

{{block content_main}}
{{use "jquery"}}
{{use "jqutils", hoverIntent=True}}

<script type="text/html" id="topicTemplate">
    <tr>
        <td align="left" class="first">${subject}</td>
        <td align="left"><cite>${posted_by}</cite><em>${created_on}</em></td>
        <td align="center"><b>${num_replies}</b>/<b>${num_views}</b></td>
        <td align="left"><cite>${last_post_user} <a href="/forum/id/${last_post}" title="跳转到最后回复">&raquo;</a></cite><em>${last_reply_on}</em></td>
    </tr>
</script>
<table class="table" id="forum-table">
    <colgroup>
        <col width="*"></col>
        <col width="100px"></col>
        <col width="100px"></col>
        <col width="150px"></col>
    </colgroup>
    <tbody>
        <tr class="linear-header">
            <th class="first">
            <span>{{=_('Filter:')}}</span>
                <div class="hover-menu">
                <cite>{{=filter_name}}<b class="caret"></b></cite>
                <ul class="items">
                    <li><a href="?filter=all">{{=_('All Subjects')}}</a></li>
                    <li><a href="?filter=essence">{{=_('Essence')}}</a></li>
                    <li><a href="?filter=sticky">{{=_('Top Subjects')}}</a></li>
                </ul>
                </div>
            </th>
            <th>{{=_('Author')}}</th>
            <th>{{=_('Subject/View')}}</th>
            <th>{{=_('Lastest Post')}}</th>
        </tr>
    {{from datetime import timedelta
    from uliweb.utils import date
    
    def is_new(d):
        if d and (d+timedelta(settings.get_var('PARA/NEW_DIFF_DAYS')))>=date.now():
            return True
        pass
    pass
    }}
    {{for item in objects:}}
        <tr>
            <td class="first">{{<< item['subject']}}
                {{if is_new(item['_obj_'].updated_on) or is_new(item['_obj_'].created_on):}}
                    <img src="/static/forums/new.png"/>
                {{pass}}
            </td>
            <td><cite>{{<< item['posted_by']}}</cite><em>{{<< item['created_on']}}</em></td>
            <td><b>{{= item['num_replies']}}</b>/<b>{{= item['num_views']}}</b></td>
            <td><cite>{{<< item['last_post_user']}} {{if is_new(item['_obj_'].last_reply_on):}}<img src="/static/forums/new.png"/>{{pass}}
            {{if item['last_post']:}}<a href="/forum/id/{{<< item['last_post']}}" title="跳转到最后回复">&raquo;</a>{{pass}}</cite><em>{{<< item['last_reply_on']}}</em></td>
        </tr>
    {{pass}}
    </tbody>
</table>
<div class="pagination pagination-centered">{{<<pagination}}</div>
<script type="text/javascript">
    $(function(){
        $('.hover-menu').hover_menu();
    });
</script>
{{end}}
